Golang flag.Uint() function example
package flag
Uint defines a uint flag with specified name(1st parameter), default value(2nd parameter), and usage string(3rd parameter). The return value is the address of a uint variable that stores the value of the flag.
Golang flag.Uint() function usage example
package main
import (
"flag"
"fmt"
"strconv"
)
func main() {
port := flag.Uint("port", 8080, "Port to listen. Default is 8080")
flag.Parse()
fmt.Println(flag.Lookup("port")) // print the Flag struct
fmt.Printf("Port number is %s\n ", strconv.Itoa(int(*port)))
}
Output :
&{port Port to listen. Default is 8080 8080 8080}
Port number is 8080
Reference :
Advertisement
Something interesting
Tutorials
+8.5k Golang : How to check if input string is a word?
+8.4k Golang : Generate Datamatrix barcode
+9.5k Mac OSX : Get a process/daemon status information
+5.1k Linux : How to set root password in Linux Mint
+7.7k Golang : Test if an input is an Armstrong number example
+9.5k Golang : Extract or copy items from map based on value
+13.1k Golang : Handle or parse date string with Z suffix(RFC3339) example
+13.8k Generate salted password with OpenSSL example
+14.5k Golang : How to determine if user agent is a mobile device example
+23.6k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date
+11.9k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example
+9.1k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference